#include "unit_test.h"
#include <cmath>
#include <cstdio>
#include <cstring>
#include <gtest/gtest.h>
#include <iterator>
#include <math.h>
#include <string>
#include <iostream>
#include <functional>
#include <memory>
#include <vector>
#include "xstack_filter_format.h"

TEST(InputFileProcess,ReadInputFile)
{
    std::vector<std::string> input_file_vec;

    input_file_vec.emplace_back("/home/hjie/data/fake/test1.mp4");
    input_file_vec.emplace_back("/home/hjie/data/fake/test2.mp4");
    input_file_vec.emplace_back("/home/hjie/data/fake/test3.mp4");
    input_file_vec.emplace_back("/home/hjie/data/fake/test4.mp4");

    // input_file_vec.emplace_back("/home/hjie/data/fake/test1.mp4");
    // input_file_vec.emplace_back("/home/hjie/data/fake/test1.mp4");

    // input_file_vec.emplace_back("/home/hjie/data/fake/test1.mp4");
    // input_file_vec.emplace_back("/home/hjie/data/fake/test1.mp4");
    // input_file_vec.emplace_back("/home/hjie/data/fake/test1.mp4");


    XstackFilterDataInfo xstack;
    //InitInputFile(input_file_vec, xstack);
    //EXPECT_EQ(input_file_vec.size(), xstack.m_input_file_map.size());
    //DumpInputData(xstack);
    //EXPECT_EQ(input_file_vec.size(),xstack.m_input_stream_map.size());
    /* XstackFilterDataInfo xstack; */
    //EXPECT_EQ(true,InitXstackFilter(xstack));
}

TEST(SqrtFuntion, TestCode)
{
    printf("%d.\n", int(floor(sqrt(2))));
    int width  = 1920;
    int height = 1080;
    int lenght = 2;
    int cols = round(sqrt(lenght));
    int rows = lenght/cols;
    int invq = (cols == 1 && rows != 1) ? cols + 1 : cols;
    int cell_width  = (width/invq);
    int cell_height = ((double)height/width) * (cell_width);
    printf("cols:%d rows:%d cell_width:%d cell_height:%d.\n", cols, rows, cell_width, cell_height);
    int width_block  = (width  - (cell_width  * rows)) / 2;
    int height_block = (height - (cell_height * cols)) / 2;
    printf("wblock:%d\thblock:%d.\n", width_block, height_block);
    struct CellData
    {
        int x;
        int y;
        int cell_width;
        int cell_height;
    };
    int floor_num = floor(sqrt(lenght));
    int x = width_block;
    int y = height_block;
    std::vector<CellData> cell_data_vec;
    for (int i = 0; i < floor_num; i++)
    {
        for (int j = 0; j < rows; j++)
        {
            CellData data;
            data.x = x;
            data.y = y;
            data.cell_height = cell_height;
            data.cell_width  = cell_width;
            y += cell_width;
            cell_data_vec.push_back(data);
        }
        x += cell_height;
    }
    int num = lenght - (floor_num * rows);
    x += (width - (num * cell_width))/2;
    for (int i = 0; i < num; i++)
    {
        CellData data;
        data.x = x;
        data.y = y;
        data.cell_width = cell_width;
        data.cell_height= cell_height;
        cell_data_vec.push_back(data);
    }
    for (auto & data : cell_data_vec)
    {
        printf("x:%d y:%d w:%d h:%d.\n", data.x, data.y, data.cell_width, data.cell_height);
    }
}

TEST(ComputeData, Data)
{
    for (int i = 1; i <= 25; i++)
    {
        int floor_data = floor(sqrt(i));
        int rows = ceil(sqrt(i));
        printf("length : %d\tcols : %d rows : %d.\n", i,floor_data,rows);
        if (floor_data * rows > i)
        {
           printf("cols : %d.\n", floor_data - 1); 
        }
    }
}



